package com.aaa.controller;

import com.aaa.entity.Inventory;
import com.aaa.service.impl.InventoryServiceimpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("inventory")
public class InventoryController {
    @Resource
    InventoryServiceimpl inventoryserviceimpl;

    @ResponseBody
    @RequestMapping("findpage")
    public Map<String, Object> userList(Integer pageSize, Integer pageNum) {
        Map<String, Object> map = new HashMap<>();
        List<Inventory> userList = inventoryserviceimpl.findpage(pageSize, pageNum * pageSize);
        Integer TotalNum = inventoryserviceimpl.pagecount();

        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }

    @RequestMapping("add")
    @ResponseBody
    public Integer add(Inventory inventory){
        return inventoryserviceimpl.add(inventory);
    }

    @RequestMapping("update")
    @ResponseBody
    public Integer update(Inventory inventory){
        return inventoryserviceimpl.update(inventory);
    }

    @ResponseBody
    @RequestMapping("page")
    public Map<String, Object> page(Integer pageSize, Integer pageNum) {
        Map<String, Object> map = new HashMap<>();
        List<Inventory> userList = inventoryserviceimpl.Inventoryrecords(pageSize, pageNum * pageSize);
        Integer TotalNum = inventoryserviceimpl.findcount();
        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }

}
